package com.crm.dao.purchaseDAO;


import com.crm.pojo.Purchase;
import com.crm.pojo.Purchasergdetail;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface PurchasergDAO extends CrudRepository<Purchasergdetail,Long>, JpaSpecificationExecutor<Purchasergdetail> {

    //分页查询所有的采购退货单
    @Query("from Purchasergdetail p  order by p.prgdate desc")
    public List<Purchasergdetail> findAllByPaged(Pageable pageable);

    //模糊查询采购退货单根据采购主题和供应商名称
    @Query(nativeQuery = true,value = "select prg.* from PURCHASERGDETAILS prg inner join PURCHASE p on prg.PURIDFK=p.PURID inner join CLIENT_INFO c on p.CLIENTID=c.CID where (p.PURTHEME like ?1 or c.CNAME like ?1)")
    public List<Purchasergdetail> findAllByMh(String q);
    //模糊查询采购退货单根据采购主题和供应商名称 采购完成-已入库
    @Query(nativeQuery = true,value = "select prg.* from PURCHASERGDETAILS prg inner join PURCHASE p on prg.PURIDFK=p.PURID inner join CLIENT_INFO c on p.CLIENTID=c.CID where (p.PURTHEME like ?1 or c.CNAME like ?1) and p.PURSTATUS='采购完成-已入库'")
    public List<Purchasergdetail> findAllByMh2(String q);
    //模糊查询采购退货单根据采购主题和供应商名称 采购完成-未入库
    @Query(nativeQuery = true,value = "select prg.* from PURCHASERGDETAILS prg inner join PURCHASE p on prg.PURIDFK=p.PURID inner join CLIENT_INFO c on p.CLIENTID=c.CID where (p.PURTHEME like ?1 or c.CNAME like ?1) and p.PURSTATUS='采购完成-待入库'")
    public List<Purchasergdetail> findAllByMh1(String q);
    //查询所有采购退货单
    @Query("from Purchasergdetail prg where prg.purchasergdetailsIsDel='退货完成-待出库'")
    public List<Purchasergdetail> findAllBymh();
}
